<template>
<div class="type-item" @click="$emit('click', type)">
    <div class="type-icon" :class="iconClass">
        <van-icon :name="icon" size="24" />
        <div class="badge" v-if="unreadCount > 0">{{ unreadCount }}</div>
    </div>
    <div class="type-name">{{ name }}</div>
</div>
</template>

<script>
export default {
    name: 'MessageTypeIcon',
    props: {
        type: {
            type: String,
            required: true,
            validator: (value) => ['likes', 'comments', 'follows', 'system'].includes(value)
        },
        unreadCount: {
            type: Number,
            default: 0
        }
    },
    computed: {
        icon() {
            const iconMap = {
                likes: 'like',
                comments: 'chat',
                follows: 'friends',
                system: 'bell'
            }
            return iconMap[this.type] || 'star'
        },
        name() {
            const nameMap = {
                likes: '赞和收藏',
                comments: '评论和@',
                follows: '新增关注',
                system: '系统通知'
            }
            return nameMap[this.type] || ''
        },
        iconClass() {
            const classMap = {
                likes: 'like-icon',
                comments: 'comment-icon',
                follows: 'follow-icon',
                system: 'system-icon'
            }
            return classMap[this.type] || ''
        }
    }
}
</script>

<style scoped>
.type-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
}

.type-icon {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 8px;
    position: relative;
}

.like-icon {
    background-color: #ffecec;
    color: #ff6b6b;
}

.follow-icon {
    background-color: #e6f7ff;
    color: #1989fa;
}

.comment-icon {
    background-color: #e8faf0;
    color: #07c160;
}

.system-icon {
    background-color: #fff8e6;
    color: #ff9500;
}

.badge {
    position: absolute;
    top: -5px;
    right: -5px;
    min-width: 16px;
    height: 16px;
    border-radius: 8px;
    background-color: #ff2442;
    color: #fff;
    font-size: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
}

.type-name {
    font-size: 12px;
    color: #333;
}
</style>